package com.example.test;

import org.springframework.context.support.SimpleThreadScope;

import java.util.concurrent.TimeUnit;

/**
 * TODO: 这里要写注释的!
 */
public class Main {
    public static void main(String[] args) {
        ThreadGroup threadGroup= new ThreadGroup("Searcher");
        Result result= new Result();
        SearchTask searchTask= new SearchTask(result);
        for (int i = 0; i <5 ; i++) {
            Thread thread= new Thread(threadGroup,searchTask);
            thread.start();
            try {
                TimeUnit.SECONDS.sleep(1);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        System.out.printf("Number of Thread：%d\n",threadGroup.activeCount());
        System.out.printf("Information about the Thread Group\n");
        waitFinish(threadGroup);
        threadGroup.interrupt();
    }
    private static void waitFinish(ThreadGroup threadGroup){
        while (threadGroup.activeCount()>9){
            try {
                TimeUnit.SECONDS.sleep(1);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
